String.prototype.trim = function () {
    return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
//注册检查用户名
function checkUserName() {
    var flag = false;
    var name = document.getElementById("username");
    if (name.value == null || name.value.trim() == "") {
        flag = false;
        $("#namemsg").html("用户名不能为空")
        name.focus();
    }
    else {
        $.ajax({
            url: "/Origami/checkUserName",
            type: "post",
            data: {userName: name.value},
            dataType: "json",
            async: false,
            complete: function (data) {
                if (data.responseText == 'no') {
                    flag = false;
                    $("#namemsg").html("用户名已存在")
                    name.focus();
                } else if (data.responseText == 'error') {
                    flag = false;
                    $('#signupalert').show();
                } else {
                    flag = true;
                    $("#namemsg").html("")
                }
            }
        })
    }

    return flag;

}
//注册检查邮箱
function checkEmail() {
    var flag = false;
    //邮箱匹配
    var filter = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    var email = document.getElementById("email");
    if (email.value == null || email.value.trim() == "") {
        flag = false;
        $("#emailmsg").html("邮箱不能为空")
        email.focus();
    } else if (!filter.test(email.value)) {
        flag = false;
        $("#emailmsg").html("邮箱格式不正确，例如:xxx@163.com")
        email.focus();
    }
    else {
        $.ajax({
            url: "/Origami/checkEmail",
            type: "post",
            data: {email: email.value},
            dataType: "json",
            async: false,
            complete: function (data) {
                if (data.responseText == 'no') {
                    flag = false;
                    $("#emailmsg").html("邮箱已存在")
                    email.focus();
                } else if (data.responseText == 'error') {
                    flag = false;
                    $('#signupalert').show();
                } else {
                    flag = true;
                    $("#emailmsg").html("")
                }
            }
        })
    }
    return flag;

}
//注册检查密码
function checkPasswd() {
    var flag = false;
    var passwd = document.getElementById("passwd1");
    if (passwd.value == null || passwd.value.trim() == "") {
        flag = false;
        $("#passwd1msg").html("密码不能为空")
        passwd.focus();
    }
    else if (passwd.value.length < 6 || passwd.value.length > 10) {
        flag = false;
        $("#passwd1msg").html("请输入6-10位的密码")
        passwd.focus();
    } else {
        flag = true;
        $("#passwd1msg").html("")
    }
    return flag;
}
//注册确认密码
function confirmPasswd() {
    var flag = false;
    var passwd1 = document.getElementById("passwd1");
    var passwd2 = document.getElementById("passwd2");
    if (passwd2.value == null || passwd2.value.trim() == "") {
        flag = false;
        $("#passwd2msg").html("请再次输入密码")
    }
    else if (passwd1.value != passwd2.value) {
        flag = false;
        $("#passwd2msg").html("两次输入的密码不一致");
    } else {
        flag = true;
        $("#passwd2msg").html("");
    }
    return flag;
}
    function gosubmit() {
        if (checkEmail() && checkUserName() && checkPasswd() && confirmPasswd()) {
            signupform.submit();
    }

}

//修改用户信息
function updateAccount(userName,userEmail) {
    var email = document.getElementById("email");
    var name = document.getElementById("username");
    var flag = false;
    if(name.value != userName){
        if(checkUserName()){
            flag = true;
        }else{
            flag = false;
        }
    }
    if(email.value != userEmail){
        if(checkEmail()){
            flag = true;
        }else{
            flag = false;
        }
    }
    return flag;
}